var express = require('express');
var router = express.Router();
var Goodslist = require("../models/goodslist");


//获取商品数据
router.get('/', function(req, res, next) {
    let page = parseInt(req.param("searchNum"));
    let pageSize = 5;
    // let sort = req.param("sort");
    let skip = (page-1)*pageSize;
    var pri = "";

    if(req.param("searchType") == "downprice"){
        pri ='-salePrice';
    }else if(req.param("searchType") == "upprice"){
        pri = 'salePrice';
    }
    let model = Goodslist.find({"shelves": true, $or:[{"goodName":{$regex: req.param("goodsName")}}]}).skip(skip).limit(pageSize).sort(pri);

        model.exec(function (err, result) {
            if (err) {
                res.json({
                    status: "1",
                    msg: err.message
                })
            } else {
                res.json({
                    status: "0",
                    msg: "",
                    result: {
                        list: result
                    }
                })
            }
        });
});


module.exports = router;